<?php
class setting_model extends jqxGrid_CI_Model {

    function __construct()
    {
        parent::__construct();
        $this->_table="adp_settings";
    }
    
    function get($_id){
        $where=array('ID'=>$_id);
        $query=$this->db->get_where($this->_table, $where); 
        return $query->result();
    }
    function getByKey($Key){
        $where=array('Key'=>$Key);
        $query=$this->db->get_where($this->_table, $where); 
        return $query->result();
    }
    function gets(){
        $where=array("Lock"=>0);
        $query=$this->db
                ->where($where)
                ->get($this->_table); 
        return $query->result();
    }
    function insert($params){
        $this->db->set('Insert', 'NOW()', FALSE);
        $this->db->insert($this->_table, $params); 
        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return true;
        return false;
    }
    function delete($_id){
        $this->db->set('Delete', 'NOW()', FALSE);
        $where=array('ID'=>$_id);
        $this->db->where($where);
        $this->db->update($this->_table); 
        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return $count;
        return false;
    }
    function retore($_id){
        $this->db->set('Delete', 'NULL', FALSE);
        $where=array('ID'=>$_id);
        $this->db->where($where);
        $this->db->update($this->_table); 
        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return $count;
        return false;
    }
    function update($_id,$params){
        $this->db->set('Update', 'NOW()', FALSE);
        $this->db->where('ID', $_id);
        $this->db->update($this->_table, $params); 
        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return $count;
        return false;
    }
    
}
?>
